<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller{
    public function login(){
        if (!IS_POST) {
            $this->display();
        }
//       var_dump(I('post.'));
//       exit();
        $user=D('User');
        if (!$user->create()){
            exit($user->getError());
        }
         // test code
        if (!($user->check_verify(I('post.code')))){
            echo '验证码输入错误';
            exit();
        }
        $info=$user->checkNamePwd(I('post.user_name'),I('post.pwd'));
        if ($info){
            session('user_name',$info['user_id']);
            session('ccode',md5(SALT.'|||'.$info['user_name']));
            session('pwd',$info['pwd']);
            $this->redirect('Index/index');
        }
    }
    /**
     * logout
     */
    public function logout(){
        session_start();
        session(null);
        $this->redirect('login');
    }
    /**
     * retrun code
     */
    public function verifyImg(){
        $config = array(
            'imageH'    =>  45,
            'imageW'    =>  100,
            'fontSIze' => 30,
            'length' => 1,
            'useNoise' => false,
            'useImgBg' => true,
        );
        $Verify=new \Think\Verify($config);
        $Verify->entry();
    }
}
